import MyIcon from '@/components/MyIcon';
import ScrollBarLayout from '@/components/ScrollBarLayout';
import { getKeyRouter, getTenantID, tooltipLength } from '@/utils';
import { Col, Empty, List, Row, Tooltip } from 'antd';
import pageStyles from '@/common/pageLayout.less';
import { history } from 'umi';
import InfiniteScroll from 'react-infinite-scroller';
import { ILoadMapTypeAll } from '@/common';
export const IntentHomeCheckPane: React.FC<IntentHomeAPI.IIntentHomeCheckPane> = ({
  styleClassName,
  intentInfoList,
  taskLoadingIntent,
  dataIntent,
  paginationIntent,
  getTaskCheckDataIntent,
  tabPaneKey,
}) => {
  /** 点击跳转 */
  const onHandleSkip = (resObj: any) => {
    history.push({
      pathname: `/purchaseSourceIntentController/dealHomePage/:${getKeyRouter()}${getKeyRouter()}`,
      state: {
        pageType: 'detail',
        id: resObj?.attributes.busi_id,
        pageInfo: {
          id: resObj?.attributes?.busi_id ? resObj?.attributes?.busi_id : null,
        },
        pIDDetailInfo: {
          ...resObj?.attributes,
          id: resObj?.attributes?.busi_id ? resObj?.attributes?.busi_id : null,
        },
      },
    });
  };
  //回调函数
  const fetchGetApplySev = () => {
    let { current, pageSize, total }: Record<string, any> = paginationIntent;
    if (dataIntent?.rows?.length < total) {
      if (tabPaneKey == '1') {
        getTaskCheckDataIntent({
          taskType: false,
          current,
          pageSize: pageSize + 10,
        });
      } else if (tabPaneKey == '2') {
        getTaskCheckDataIntent({
          // state: `${getTenantID()}${ILoadMapTypeAll.CONTRACT_STATE}1003`
          checkState: `${getTenantID()}${ILoadMapTypeAll.ALLFLOW_CHECKRESULT}1001`,
          current,
          pageSize: pageSize + 10,
        });
      } else if (tabPaneKey == '3') {
        getTaskCheckDataIntent({
          state: `${getTenantID()}${ILoadMapTypeAll.DISCLOSURE_STATE}1000`,
          current,
          pageSize: pageSize + 10,
        });
      } else if (tabPaneKey == '4') {
        getTaskCheckDataIntent({
          taskType: true,
          current,
          pageSize: pageSize + 10,
        });
      }
    }
  };
  return (
    <div className="commonTabsBodyDom" style={{ padding: '5px 0px' }}>
      {intentInfoList && intentInfoList?.length > 0 ? (
        <div className={pageStyles['InfiniteScrollView']}>
          <InfiniteScroll
            pageStart={1}
            className="InfiniteScrollDiv"
            useWindow={false}
            initialLoad={false}
            loadMore={fetchGetApplySev}
            hasMore={!taskLoadingIntent}
            style={{ padding: 8 }}
          >
            <List
              itemLayout="horizontal"
              dataSource={intentInfoList}
              className={`${styleClassName}-homeListSty`}
              renderItem={(item) => {
                return (
                  <List.Item
                    onClick={() => {
                      onHandleSkip(item);
                    }}
                  >
                    <List.Item.Meta
                      avatar={
                        <div>
                          <MyIcon type="icon-solution1" style={{ fontSize: '40px' }} />
                        </div>
                      }
                      title={
                        <Tooltip placement="topLeft" title={tooltipLength(item?.attributes?.busi_purchProjectName, 50)}>
                          <div className={`${styleClassName}-homeListSty-titleDiv`}>
                            <a className={pageStyles['over-flow-hidden']}>{item?.attributes?.busi_purchProjectName || '--'}</a>
                            <div style={{ whiteSpace: 'nowrap', marginLeft: 10 }}>{item?.attributes?.busi_createTime?.split(' ')?.[0] || '--'}</div>
                          </div>
                        </Tooltip>
                      }
                      description={
                        <Row>
                          <Col span={18}>
                            <div className={pageStyles['over-flow-hidden']}>{item?.attributes?.busi_purchaseInfo || '--'}</div>
                          </Col>
                          <Col span={6}>
                            <div className={pageStyles['over-flow-hidden']} style={{ textAlign: 'right', width: '100%' }}>
                              {item?.attributes?.busi_createDepartmentName || '--'}
                            </div>
                          </Col>
                        </Row>
                      }
                    />
                  </List.Item>
                );
              }}
            />
          </InfiniteScroll>
        </div>
      ) : (
        <Empty image={Empty.PRESENTED_IMAGE_SIMPLE} />
      )}
    </div>
  );
};
